package com.czxy.service;

import cn.itcast.commons.CommonUtils;
import com.czxy.dao.UserMapper;
import com.czxy.domain.User;
import com.czxy.utils.MyBatisUtils;

import java.util.List;

public class UserService {

    /**
     * 登录功能
     * @param user
     * @return
     */
    public User login(User user){

        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        User loginU = mapper.login(user);
        MyBatisUtils.close();
        return loginU;

    }

    /**
     * 注册逻辑
     * @param user
     */
    public void register(User user){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        user.setUid(CommonUtils.uuid());
         mapper.insert(user);
         MyBatisUtils.commitAndClose();

    }


    /**
     * 根据用户名 获取用户数据
     * @param username
     * @return
     */
    public List<User> findUserByUsername(String username){
        UserMapper mapper = MyBatisUtils.getMapper(UserMapper.class);
        List<User> users = mapper.findUserByUsername(username);
        MyBatisUtils.close();
        return users;

    }
}
